package com.carkeeper.order.controller;

import com.carkeeper.common.utils.PageResult;
import com.carkeeper.common.utils.Result;
import com.carkeeper.common.utils.StatusCode;
import com.carkeeper.order.pojo.Order;
import com.carkeeper.order.pojo.OrderGroup;
import com.carkeeper.order.service.OrderService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/serviceOrder")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询服务订单信息
     *
     * @param searchMap
     * @return
     */
    @GetMapping(value = "/order")
    public Map findPage(@RequestParam Map searchMap) {
        Map resultMap = orderService.findPage(searchMap);
        //PageResult pageResult = new PageResult(pageList.getTotal(),pageList.getResult());
        return resultMap;
    }

    /**
     * 查询待处理订单
     *
     * @return
     */
    @GetMapping(value = "/pending/{page}/{size}")
    public Result pendingAll(@RequestParam Map searchMap, int orderStatus, @PathVariable int page, @PathVariable int size) {
        Page<Order> pageList = orderService.pendingAll(searchMap, orderStatus, page, size);
        PageResult pageResult = new PageResult(pageList.getTotal(), pageList.getResult());
        return new Result(true, StatusCode.OK, "查询待处理订单", pageResult);
    }

    /**
     * 点击查看
     *
     * @return
     */
    @GetMapping("/viewAll")
    public Result viewAll(@RequestParam String id) {
        OrderGroup orderGroup = orderService.viewAll(id);
        return new Result(true, StatusCode.OK, "查询成功", orderGroup);
    }

    @GetMapping(value = "/findOrders")
    public List<Order> findOrders(@RequestParam Map searchMap) {
        List<Order> orderList = orderService.findOrders(searchMap);
        return orderList;
    }

    @GetMapping("/findMoneyByDate")
    public List findMoneyByDate(@RequestParam Map map) throws ParseException {
        List list = orderService.findMoneyByDate(map);
        return list;
    }

    /*    *//**
     * 查询车主信息（点击查看）
     *
     * @param code
     * @return
     *//*
    @GetMapping(value = "/look")
    public Result lookAll(@RequestParam String code) {
        Map map = orderService.lookAll(code);
        return new Result(true, StatusCode.OK, "查询车主信息成功", map);
    }

    *//**
     * 查询服务商信息（点击查看）
     *
     * @param
     * @return
     *//*
    @GetMapping(value = "/subject/{id}")
    public Result subject(@PathVariable("id") Long id) {
        Map map = orderService.findByOrderStoreId(id);
        return new Result(true, StatusCode.OK, "查询服务商信息成功", map);

    }

    *//**
     * 查询操作记录（点击查看）
     *
     * @return
     *//*
    @GetMapping(value = "/operating")
    public Result<OrderLog> operating(@RequestParam String id) {
        OrderLog orderLog = orderService.findByOrderId(id);
        return new Result(true, StatusCode.OK, "查询操作记录信息成功", orderLog);
    }*/
}
